package edu.hit.irlab.coref.corpus.converter;

import java.io.File;
import java.util.ArrayList;

import org.dom4j.Document;

/**
 * @author gaga.zhn
 *
 */

public abstract class Converter {
	public static final String DOCUMENT = "document";
	public static final String DOCID = "DOCID";
	public static final String ID = "ID";
	//entity constants
	public static final String ENTITY = "entity";
	public static final String ENTITY_TYPE = "TYPE";
	public static final String ENTITY_SUBTYPE = "SUBTYPE";
	public static final String ENTITY_CLASS = "CLASS";
	public static final String PARENTID = "PARENTID";
	//mention constants
	public static final String MENTION = "mention";
	public static final String MENTION_TYPE = "TYPE";
	public static final String EXTENT = "extent";
	public static final String HEAD = "HEAD";
	public static final String START = "START";
	public static final String END = "END";
	
	/*	the key interface to transform XML file to a Dom tree */
	abstract public Document transform(File remoteXML); 
	
	/*	get the text content by checking the dom's DOCID */
	abstract public String getDocumentString(Document doc, String sourceDocPath);
	
	/* process multi-files*/
	public Document[] transform(String remoteXMLPath) {
		ArrayList<Document> array = new ArrayList<Document>();
		
		File dir = new File(remoteXMLPath);
		if (dir.isDirectory()) {
			for (File file : dir.listFiles()) {
				array.add(transform(file));
			}
		} else {
			array.add(transform(dir));
		}
		
		return array.toArray(new Document[]{});
	}
	
	/* the text-content files are in the current direction */
	public String getDocumentString(Document doc) {
		return getDocumentString(doc, null);
	}
}
